﻿using System.Reflection;

namespace Borg
{
    internal static class TaskFactory
    {
        public const uint UNDEFINED_TASK_ID = 4294967295U;

        private static uint _nextTaskGroupId;

        internal static uint CreateTaskGroupId()
        {
            return _nextTaskGroupId++;
        }

        internal static ITask CreateShutdown(uint taskGroupId, Assembly initiator)
        {
            return new ShutdownTask(taskGroupId, initiator);
        }

        internal static ITask CreateAddContract(Repository obj, ContractInfo contractInfo,
            uint taskGroupId, Assembly initiator)
        {
            return new AddContractTask(obj, contractInfo, taskGroupId, initiator);
        }

        internal static ITask CreateRemoveContract(Repository obj, ContractInfo contractInfo,
            uint taskGroupId, Assembly initiator)
        {
            return new RemoveContractTask(obj, contractInfo, taskGroupId, initiator);
        }

        internal static ITask CreateAddPlugin(Repository obj, PluginInfo pluginInfo,
            uint taskGroupId, Assembly initiator)
        {
            return new AddPluginTask(obj, pluginInfo, taskGroupId, initiator);
        }

        internal static ITask CreateRemovePlugin(Repository obj, PluginInfo pluginInfo,
            uint taskGroupId, Assembly initiator)
        {
            return new RemovePluginTask(obj, pluginInfo, taskGroupId, initiator);
        }

        internal static ITask CreateRegister(PluginInfo obj, bool isManual,
            uint taskGroupId, Assembly initiator)
        {
            return new RegisterPluginTask(obj, isManual, taskGroupId, initiator);
        }

        internal static ITask CreateDeregister(PluginInfo obj,
            uint taskGroupId, Assembly initiator)
        {
            return new DeregisterPluginTask(obj, taskGroupId, initiator);
        }

        internal static ITask CreateRegisterPlugs(ExtensionTypeInfo obj,
            bool isManual, uint taskGroupId, Assembly initiator)
        {
            return new RegisterPlugsTask(obj, isManual, taskGroupId, initiator);
        }

        internal static ITask CreateDeregisterPlugs(ExtensionTypeInfo obj,
            uint taskGroupId, Assembly initiator)
        {
            return new DeregisterPlugsTask(obj, taskGroupId, initiator);
        }

        internal static ITask CreatePlug(ExtensionTypeInfo obj, ExtensionInfo ei,
            uint taskGroupId, Assembly initiator)
        {
            return new ExtensionTypePlugTask(obj, ei, taskGroupId, initiator);
        }

        internal static ITask CreateOpenSlots(ExtensionInfo obj, bool isManual,
            uint taskGroupId, Assembly initiator)
        {
            return new OpenSlotsTask(obj, isManual, taskGroupId, initiator);
        }

        internal static ITask CreateCloseSlots(ExtensionInfo obj,
            uint taskGroupId, Assembly initiator)
        {
            return new CloseSlotsTask(obj, taskGroupId, initiator);
        }

        internal static ITask CreateRegisterInSlots(ExtensionInfo obj,
            bool isManual, uint taskGroupId, Assembly initiator)
        {
            return new RegisterInSlotsTask(obj, null, isManual, taskGroupId, initiator);
        }

        internal static ITask CreateRegisterInSlots(ExtensionInfo obj,
            ExtensionTypeInfo eti, bool isManual, uint taskGroupId, Assembly initiator)
        {
            return new RegisterInSlotsTask(obj, eti, isManual, taskGroupId, initiator);
        }

        internal static ITask CreateDeregisterFromSlots(ExtensionInfo obj,
            uint taskGroupId, Assembly initiator)
        {
            return new DeregisterFromSlotsTask(obj, null, taskGroupId, initiator);
        }

        internal static ITask CreateDeregisterFromSlots(ExtensionInfo obj,
            ExtensionTypeInfo eti, uint taskGroupId, Assembly initiator)
        {
            return new DeregisterFromSlotsTask(obj, eti, taskGroupId, initiator);
        }

        internal static ITask CreatePlugInSlots(ExtensionInfo obj, bool isManual,
            uint taskGroupId, Assembly initiator)
        {
            return new PlugInSlotsTask(obj, null, isManual, taskGroupId, initiator);
        }

        internal static ITask CreatePlugInSlots(ExtensionInfo obj, ExtensionTypeInfo eti,
            bool isManual, uint taskGroupId, Assembly initiator)
        {
            return new PlugInSlotsTask(eti, obj, isManual, taskGroupId, initiator);
        }

        internal static ITask CreatePlugInSlots(ExtensionInfo obj, ExtensionInfo pluggingEi,
            bool isManual, uint taskGroupId, Assembly initiator)
        {
            return new PlugInSlotsTask(obj, pluggingEi, isManual, taskGroupId, initiator);
        }

        internal static ITask CreatePlugPlugs(ExtensionInfo obj, bool isManual,
            uint taskGroupId, Assembly initiator, ExtensionInfo ignoreExt)
        {
            return new PlugPlugsTask(obj, null, isManual, taskGroupId, initiator, ignoreExt);
        }

        internal static ITask CreatePlugPlugs(ExtensionInfo obj, ExtensionInfo ei,
            bool isManual, uint taskGroupId, Assembly initiator)
        {
            return new PlugPlugsTask(obj, ei, isManual, taskGroupId, initiator, null);
        }

        internal static ITask CreateUnplugFromSlots(ExtensionInfo obj,
            uint taskGroupId, Assembly initiator)
        {
            return new UnplugFromSlotsTask(obj, null, taskGroupId, initiator);
        }

        internal static ITask CreateUnplugFromSlots(ExtensionInfo obj,
            ExtensionInfo unpluggingEi, uint taskGroupId, Assembly initiator)
        {
            return new UnplugFromSlotsTask(obj, unpluggingEi, taskGroupId, initiator);
        }

        internal static ITask CreateUnplugPlugs(ExtensionInfo obj,
            uint taskGroupId, Assembly initiator)
        {
            return new UnplugPlugsTask(obj, null, taskGroupId, initiator);
        }

        internal static ITask CreateUnplugPlugs(ExtensionInfo obj,
            ExtensionInfo ei, uint taskGroupId, Assembly initiator)
        {
            return new UnplugPlugsTask(obj, ei, taskGroupId, initiator);
        }

        internal static ITask CreateRelease(ExtensionInfo obj,
            uint taskGroupId, Assembly initiator)
        {
            return new ReleaseTask(obj, taskGroupId, initiator);
        }

        internal static ITask CreateOpenSlot(SlotInfo obj, bool isManual,
            uint taskGroupId, Assembly initiator)
        {
            return new OpenSlotTask(obj, isManual, taskGroupId, initiator);
        }

        internal static ITask CreateCloseSlot(SlotInfo obj,
            uint taskGroupId, Assembly initiator)
        {
            return new CloseSlotTask(obj, taskGroupId, initiator);
        }

        internal static ITask CreateRegister(SlotInfo obj, bool isManual,
            uint taskGroupId, Assembly initiator)
        {
            return new SlotRegisterTask(obj, null, isManual, taskGroupId, initiator);
        }

        internal static ITask CreateRegister(SlotInfo obj, PlugTypeInfo pti,
            bool isManual, uint taskGroupId, Assembly initiator)
        {
            return new SlotRegisterTask(obj, pti, isManual, taskGroupId, initiator);
        }

        internal static ITask CreateRegister(PlugTypeInfo obj, bool isManual,
            uint taskGroupId, Assembly initiator)
        {
            return new PlugTypeRegisterTask(obj, null, isManual, taskGroupId, initiator);
        }

        internal static ITask CreateRegister(PlugTypeInfo obj, SlotInfo si,
            bool isManual, uint taskGroupId, Assembly initiator)
        {
            return new PlugTypeRegisterTask(obj, si, isManual, taskGroupId, initiator);
        }

        internal static ITask CreateDeregister(SlotInfo obj,
            uint taskGroupId, Assembly initiator)
        {
            return new SlotDeregisterTask(obj, null, taskGroupId, initiator);
        }

        internal static ITask CreateDeregister(SlotInfo obj, PlugTypeInfo pti,
            uint taskGroupId, Assembly initiator)
        {
            return new SlotDeregisterTask(obj, pti, taskGroupId, initiator);
        }

        internal static ITask CreateDeregister(PlugTypeInfo obj,
            uint taskGroupId, Assembly initiator)
        {
            return new PlugTypeDeregisterTask(obj, null, taskGroupId, initiator);
        }

        internal static ITask CreateDeregister(PlugTypeInfo obj, SlotInfo si,
            uint taskGroupId, Assembly initiator)
        {
            return new PlugTypeDeregisterTask(obj, si, taskGroupId, initiator);
        }

        internal static ITask CreatePlug(PlugTypeInfo obj, SlotInfo si,
            uint taskGroupId, Assembly initiator)
        {
            return new PlugTypePlugTask(obj, si, taskGroupId, initiator);
        }

        internal static ITask CreatePlug(SlotInfo obj, bool isManual,
            uint taskGroupId, Assembly initiator)
        {
            return new SlotPlugTask(obj, null, null, isManual, taskGroupId, initiator);
        }

        internal static ITask CreatePlug(SlotInfo obj, PlugInfo pi, bool isManaual,
            uint taskGroupId, Assembly initiator)
        {
            return new SlotPlugTask(obj, pi, null, isManaual, taskGroupId, initiator);
        }

        internal static ITask CreatePlug(SlotInfo obj, PlugTypeInfo pti,
            bool isManaual, uint taskGroupId, Assembly initiator)
        {
            return new SlotPlugTask(obj, null, pti, isManaual, taskGroupId, initiator);
        }

        internal static ITask CreatePlug(PlugInfo obj, bool isManual,
            uint taskGroupId, Assembly initiator)
        {
            return new PlugPlugTask(obj, null, isManual, taskGroupId, initiator);
        }

        internal static ITask CreatePlug(PlugInfo obj, SlotInfo si,
            bool isManual, uint taskGroupId, Assembly initiator)
        {
            return new PlugPlugTask(obj, si, isManual, taskGroupId, initiator);
        }

        internal static ITask CreateUnplug(SlotInfo obj,
            uint taskGroupId, Assembly initiator)
        {
            return new SlotUnplugTask(obj, null, taskGroupId, initiator);
        }

        internal static ITask CreateUnplug(SlotInfo obj, PlugInfo pi,
            uint taskGroupId, Assembly initiator)
        {
            return new SlotUnplugTask(obj, pi, taskGroupId, initiator);
        }

        internal static ITask CreateUnplug(PlugInfo obj,
            uint taskGroupId, Assembly initiator)
        {
            return new PlugUnplugTask(obj, null, taskGroupId, initiator);
        }

        internal static ITask CreateUnplug(PlugInfo obj, SlotInfo si,
            uint taskGroupId, Assembly initiator)
        {
            return new PlugUnplugTask(obj, si, taskGroupId, initiator);
        }
    }
}

